package br.cn.evo.controller;

import br.cn.evo.util.EPRandom;
import br.cn.evo.util.EnumTypes.Function;

public class Mutation {
	public static double doValueMutation(Function function, double value,
			double step, int i) {
		// muta��o com limite da fun��o
		double max = Fitness.getMax(function, i);
		double min = Fitness.getMin(function, i);

		double alpha = 0.3;
		
		//double mutated = value + (alpha * step * EPRandom.gaussianRandomFunction());
		double mutated = value + (step * EPRandom.gaussianRandomFunction());

		if (mutated >= max)
			mutated = max;
		if (mutated <= min)
			mutated = min;

		// muta��o sem limite da fun��o
		// double mutated = value + ( step * EPRandom.gaussianRandomFunction()
		// );
		return mutated;
	}

	public static double doStepMutationLognormal(Function function, double step) {
		// muta��o com limite da fun��o
		double max = Fitness.getMax(function, null);
		double min = Fitness.getMin(function, null);

		double mutated = step + EPRandom.gaussianRandomFunction();

		if (mutated >= max)
			mutated = max;
		if (mutated <= min)
			mutated = min;

		// Muta��o sem limite de fun��o
		// double mutated = step + EPRandom.gaussianRandomFunction();
		return mutated;
	}

	public static double doStepMutationAdaptive(Function function, double step,
			double alpha, int i) {
		// muta��o com limite da fun��o
		double max = Fitness.getMax(function, i);
		double min = Fitness.getMin(function, i);

		double mutated = step + (step * alpha * EPRandom.gaussianRandomFunction());

		if (mutated >= max)
			mutated = max;
		if (mutated <= min)
			mutated = min;

		// Muta��o sem limite de fun��o
		// double mutated = step + EPRandom.gaussianRandomFunction();
		return mutated;
	}
}
